package com.smartcity.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smartcity.domain.dto.PageDTO;
import com.smartcity.domain.dto.UserDTO;
import com.smartcity.domain.po.User;
import com.smartcity.domain.query.UserQuery;
import com.smartcity.mapper.UserMapper;
import com.smartcity.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author chen
 * @since 2024-08-17
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public List<UserDTO> queryUserPage(UserQuery userQuery) {
        Page<User> page = userQuery.page();
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<User>()
                .like(userQuery.getName() != null, User::getName, userQuery.getName())
                .eq(userQuery.getSex() != null, User::getSex, userQuery.getSex())
                .like(userQuery.getNickname() != null, User::getNickname, userQuery.getNickname())
                .like(userQuery.getTel() != null, User::getTel, userQuery.getTel());
        List<User> list = list(page, wrapper);
        return BeanUtil.copyToList(list,UserDTO.class);

    }
}
